<!--分享到组件-->
<template>
  <section class="to-more" v-if="isShow">
    <div class="bg" @click="back"></div>
    <div class="cont" @click.stop="">
      <div class="hd">
        <p>分享到</p>
        <div @click.stop="back" class="close">
          <i></i>
          <i></i>
        </div>
      </div>
      <p class="pdv-2"></p>
      <div class="bd">
        <div class="icons-btn-wrap">
          <div class="item" @click="shareToWx">
            <i class="icon icon-wx"></i>
            <p class="text">微信好友</p>
          </div>
          <div class="item" @click="shareToPyq">
            <i class="icon icon-pyq"></i>
            <p class="text">朋友圈</p>
          </div>
          <div class="item" @click="shareToHyq">
            <i class="icon icon-hyq"></i>
            <p class="text">红友圈</p>
          </div>
          <div class="item" @click="shareToZbkj">
            <i class="icon icon-zbkj"></i>
            <p class="text">支部空间-资料</p>
          </div>
        </div>
      </div>
    </div>
  </section>
</template>

<script>
import StorageKeys from '@/common/const/StorageKeys'
export default {
  name: "shareTo",
  props: ["newsId", "newsTitle", "type", "listPic","listPicOss"],
  data() {
    return {
      disable: false,
      isShow: true,
      content: "",
      memorabiliaData:''
    };
  },
  created() {
    this.memorabiliaData = this.$localStorage.get(StorageKeys.MEMORABILIA_DATA)
    this.disable = false;
  },
  methods: {
    // 分享后增加积分
    addScore(url) {
      let data = {
        linkContentId: this.newsId,
        source: 0,
        linkContent: url,
        linkPhoto: this.listPic,
        ownSource: this.type,
        linkPhotoOss: this.listPicOss,
      }
      this.fetchService.linkShare(data).then((res) => {
        if (res.code !== 0) {
          return this.tools.tip(res.message);
        }
        console.log('增加积分成功')
      });
    },
    // 分享到微信好友
    shareToWx() {
      // 0：分享给好友，1：分享到朋友圈
    // * @param text 分享内容，链接分享时代表标题
    //   * @param description 分享描述
    //   * @param where 分享到哪里：0微信好友，1朋友圈
    //   * @param shareType 分享类型 0：内容分享；1：链接分享
    //   * @param url 分享链接
      let url = ''
      if(this.type === 0){//0 新闻
        url = 'http://www.djhy.gov.cn/share/news.html?newsId='+this.newsId
      }else if(this.type === 1){//1 视频
        url = 'http://www.djhy.gov.cn/share/video.html?newsId='+ this.newsId
      }else if(this.type === 6) {//6 红云FM
        url = 'http://www.djhy.gov.cn/share/audio.html?newsId='+ this.newsId
      }else if(this.type === 7) {//7 组工信息
        url = 'http://www.djhy.gov.cn/share/group.html?newsId='+ this.newsId
      }
      console.log('分享给好友')
      if (window.android && window.android.shareContentToWx) {
        window.android.shareContentToWx(this.newsTitle, this.newsTitle, 0, 1, url)
        this.addScore(url);
      }
      this.back();
    },
    // 分享到朋友圈
    shareToPyq() {
      console.log('分享到朋友圈')
      let url = ''
      if(this.type === 0){//0 新闻
        url = 'http://www.djhy.gov.cn/share/news.html?newsId='+this.newsId
      }else if(this.type === 1){//1 视频
        url = 'http://www.djhy.gov.cn/share/video.html?newsId='+ this.newsId
      }else if(this.type === 6) {//6 红云FM
        url = 'http://www.djhy.gov.cn/share/audio.html?newsId='+ this.newsId
      }else if(this.type === 7) {//7 组工信息
        url = 'http://www.djhy.gov.cn/share/group.html?newsId='+ this.newsId
      }
      if (window.android && window.android.shareContentToWx) {
        window.android.shareContentToWx(this.newsTitle, this.newsTitle, 1, 1, url)
        this.addScore(url);
      }
      this.back();
    },
    // 分享到红友圈
    shareToHyq() {
      this.back();
      if (!this.shareDialogInstance) {
        this.shareDialogInstance = this.$createShareDialog({
          $props: {
            newsId: this.newsId,
            newsTitle: this.newsTitle,
            type: this.type,
            listPic: this.listPic,
            sharePhotoOss: this.listPicOss,
          },
          $events: {
            onSuccess: (res, params) => {
              //行为记录
              this.$emit('actionPush',4)
              //行为记录结束
              this.goTo("redfriendscircle","红友圈")
            }
          }
        })
      }
      this.shareDialogInstance.show();
    },
    // 分享到部空间-资料
    shareToZbkj() {
      let routerUrl =''
      if(this.type === 0){//0 新闻
        routerUrl = "/redCloudNewsDetail/" + this.newsId + '?source='+ this.type
      }else if(this.type === 1){//1 视频
        routerUrl = "/videoDetail?id=" + this.newsId +'&zhuanji=1&source='+ this.type
      }else if(this.type === 2){//2 支部大事记(暂不需要)
        routerUrl = this.newsId+'?source='+ this.type
      }else if(this.type === 3){//3 支部相册(暂不需要)
        routerUrl = this.newsId+'?source='+ this.type
      }else if(this.type === 4){//4 学习体会(暂不需要)
        routerUrl = this.newsId+'?source='+ this.type
      }else if(this.type === 5) {//5 学习资料
        routerUrl = "/branchMemorabiliaDetail/" + this.newsId +'/'+ this.type+'?source='+ this.type
      }else if(this.type === 6) {//6 红云FM
        routerUrl = "/videoDetail?id=" + this.newsId +'&zhuanji=1&source='+ this.type
      }else if(this.type === 7) {//7 组工信息
        routerUrl = "/groupInfoDetail?id=" + this.newsId +'&source='+ this.type
      }else if(this.type === 8) {//8 播客
        routerUrl = "/redCloudNewsDetail/" + this.newsId + '?source='+ this.type
      }
      console.log('this.typethis.type=',this.type);
      this.back();
      let params={//来源（0 新闻 1 视频 2 支部大事记 3 支部相册 4 学习体会 5 学习资料 6 红云FM 7 组工信息 8 播客）
        externalUrl: routerUrl,
        title: this.newsTitle
      }
      this.tools.showLoading("正在分享...");
      this.fetchService.topic_shareToZl(params).then((res) => {
        this.tools.hideLoading();
        if (res.code !== 0) {
          return this.tools.tip(res.message);
        }
        this.$emit('actionPush',4)
        this.goTo("branchSpace","支部空间")
        // this.tools.tip("分享成功");
      });
    },
    goTo(type,page){//跳转至指定页面
      let _this = this
      this.$createDialog({
        type: 'confirm',
        title: "跳转提示",
        content: '分享成功，是否前往'+page+'？',
        confirmBtn: {
          text: '确定',
          active: true,
          disabled: false,
          href: 'javascript:;'
        },
        cancelBtn: {
          text: '取消',
          active: false,
          disabled: false,
          href: 'javascript:;'
        },
        onConfirm: () => {
          if(type ==='branchSpace'){
            this.$store.state.branchIndex = 5 //设置跳转到资料的tab栏
            return  this.$router.push({path: `/branchSpace/${this.memorabiliaData.id}`})
          }
          console.log('type',type);
          if(type ==='redfriendscircle'){
            return this.$router.replace({path: `/redfriendscircle/home?refresh`});//refresh 刷新
          }
        },
        onCancel: () => {
        }
      }).show()
    },
    show() {
      this.isShow = true;
    },
    back() {
      this.isShow = false;
    },
  },
};
</script>
<style scoped lang="scss">
@import "@/common/stylus/moon.scss";

.to-more {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  bottom: 0;
  z-index: 99;
  .bg {
    @include fullImg();
    background: rgba(0, 0, 0, 1);
    opacity: 0.5;
  }
  .cont {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: #fff;
    border-top-left-radius: pxToRem(10px);
    border-top-right-radius: pxToRem(10px);
    padding: pxToRem(25px) pxToRem(40px) pxToRem(40px);
    .hd {
      font-size: pxToRem(30px);
      font-weight: 400;
      color: rgba(51, 51, 51, 1);
      display: flex;
      justify-content: space-between;
      align-items: center;
      >p{
        width: 100%;
        text-align: center;
        font-size: pxToRem(30px);
      }
      .close {
        width: pxToRem(30px);
        height: pxToRem(30px);
        position: relative;
        transform: rotate(45deg);
        i {
          background: #999;
          position: absolute;
        }
        i:first-child {
          top: 50%;
          left: 0;
          margin-top: -1px;
          width: pxToRem(30px);
          height: 2px;
        }
        i:last-child {
          top: 0;
          left: 50%;
          margin-left: -1px;
          height: pxToRem(30px);
          width: 2px;
        }
      }
    }
    .bd {
      font-size: $defaultFontSize;
      padding: pxToRem(30px) 0;
      .icons-btn-wrap {
        display:flex;
        justify-content:space-between;
        align-items:center;
        flex-shrink:0;
        .item{
          width:pxToRem(166px);
          text-align: center;
          .text{
            font-size: pxToRem(24px);
            color: #333333;
          }
          .icon {
            display:inline-block;
            width:pxToRem(84px);
            height:pxToRem(84px);
            flex-shrink:0;
            background:url('') no-repeat center;
            background-size: 100% 100%;
            position: relative;

            &.icon-wx {background-image: url("../../../static/images/dangjian/home/news/icon-weixin.png");}
            &.icon-pyq {background-image: url("../../../static/images/dangjian/home/news/icon-pengyouquan.png");}
            &.icon-hyq {background-image: url("../../../static/images/dangjian/home/news/icon-hongyouquan.png");}
            &.icon-zbkj {background-image: url("../../../static/images/dangjian/home/news/icon-zhibukongjian.png");
            }
          }
        }
      }
    }
  }
}
.click-disable {
  pointer-events: none;
}
</style>
